# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import datetime
import json

# useful for handling different item types with a single interface
from itemadapter import ItemAdapter



class ArticalPipeline:
    def open_spider(self, spider):
        artical_filename = "{}.txt".format(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
        self.file = open(artical_filename, 'a', encoding='utf-8')


    def process_item(self, item, spider):
        line = json.dumps(dict(item), ensure_ascii=False)
        self.file.write(line)
        return item

    def close_spider(self, spider):
        self.file.close()